import { Form, Input, Modal } from "antd"
import React from "react"
import type { Task } from "../types/task"

interface TaskModalProps {
  visible: boolean
  onCancel: () => void
  onOk: (values: {
    name: string
    description?: string
    template?: string
  }) => void
  form: any
  editingTask?: Task | null
}

const TaskModal: React.FC<TaskModalProps> = ({
  visible,
  onCancel,
  onOk,
  form,
  editingTask,
}) => (
  <Modal
    open={visible}
    title={editingTask ? "编辑任务" : "新建任务"}
    onCancel={onCancel}
    onOk={() => form.submit()}
    destroyOnClose
  >
    <Form
      form={form}
      layout="vertical"
      initialValues={editingTask || { name: "", description: "", template: "" }}
      onFinish={onOk}
    >
      <Form.Item
        name="name"
        label="任务名称"
        rules={[{ required: true, message: "请输入任务名称" }]}
      >
        <Input />
      </Form.Item>
      <Form.Item name="description" label="描述">
        <Input.TextArea rows={2} />
      </Form.Item>
      <Form.Item name="template" label="模板">
        <Input />
      </Form.Item>
    </Form>
  </Modal>
)

export default TaskModal
